/******************************************************************************
 * Copyright 2023 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

#pragma once

#include "modules/canbus_vehicle/x3epro/proto/x3epro.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"

namespace apollo {
namespace canbus {
namespace x3epro {

class Adsdrivecommand50 : public ::apollo::drivers::canbus::ProtocolData<
                    ::apollo::canbus::X3epro> {
 public:
  static const int32_t ID;

  Adsdrivecommand50();

  uint32_t GetPeriod() const override;

  void Parse(const std::uint8_t* bytes, int32_t length,
                     X3epro* chassis) const override;

  void UpdateData(uint8_t* data) override;
  void UpdateData_Heartbeat(uint8_t* data) override;

  void Reset() override;

  // config detail: {'bit': 0, 'enum': {0: 'DRIVE_ENABLE_INVALID', 1: 'DRIVE_ENABLE_VALID'}, 'is_signed_var': False, 'len': 1, 'name': 'Drive_Enable', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
  Adsdrivecommand50* set_drive_enable(Ads_drive_command_50::Drive_enableType drive_enable);

  // config detail: {'bit': 9, 'enum': {0: 'AUTO_SHIFT_COMMAND_N', 1: 'AUTO_SHIFT_COMMAND_D', 2: 'AUTO_SHIFT_COMMAND_R', 3: 'AUTO_SHIFT_COMMAND_RESERVED'}, 'is_signed_var': False, 'len': 2, 'name': 'AUTO_Shift_Command', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
  Adsdrivecommand50* set_auto_shift_command(Ads_drive_command_50::Auto_shift_commandType auto_shift_command);

  // config detail: {'bit': 23, 'is_signed_var': False, 'len': 16, 'name': 'AUTO_Drive_Torque', 'offset': -665.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 0.02, 'type': 'double'}
  Adsdrivecommand50* set_auto_drive_torque(double auto_drive_torque);

  // config detail: {'bit': 51, 'is_signed_var': False, 'len': 4, 'name': 'AUTO_DriverCmd_AliveCounter', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
  Adsdrivecommand50* set_auto_drivercmd_alivecounter(int auto_drivercmd_alivecounter);

  // config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name': 'AUTO_DriverCmd_CheckSum', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
  Adsdrivecommand50* set_auto_drivercmd_checksum(int auto_drivercmd_checksum);

 private:

  // config detail: {'bit': 0, 'enum': {0: 'DRIVE_ENABLE_INVALID', 1: 'DRIVE_ENABLE_VALID'}, 'is_signed_var': False, 'len': 1, 'name': 'Drive_Enable', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
  void set_p_drive_enable(uint8_t* data, Ads_drive_command_50::Drive_enableType drive_enable);

  // config detail: {'bit': 9, 'enum': {0: 'AUTO_SHIFT_COMMAND_N', 1: 'AUTO_SHIFT_COMMAND_D', 2: 'AUTO_SHIFT_COMMAND_R', 3: 'AUTO_SHIFT_COMMAND_RESERVED'}, 'is_signed_var': False, 'len': 2, 'name': 'AUTO_Shift_Command', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
  void set_p_auto_shift_command(uint8_t* data, Ads_drive_command_50::Auto_shift_commandType auto_shift_command);

  // config detail: {'bit': 23, 'is_signed_var': False, 'len': 16, 'name': 'AUTO_Drive_Torque', 'offset': -665.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 0.02, 'type': 'double'}
  void set_p_auto_drive_torque(uint8_t* data, double auto_drive_torque);

  // config detail: {'bit': 51, 'is_signed_var': False, 'len': 4, 'name': 'AUTO_DriverCmd_AliveCounter', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
  void set_p_auto_drivercmd_alivecounter(uint8_t* data, int auto_drivercmd_alivecounter);

  // config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name': 'AUTO_DriverCmd_CheckSum', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
  void set_p_auto_drivercmd_checksum(uint8_t* data, int auto_drivercmd_checksum);

  Ads_drive_command_50::Drive_enableType drive_enable(const std::uint8_t* bytes, const int32_t length) const;

  Ads_drive_command_50::Auto_shift_commandType auto_shift_command(const std::uint8_t* bytes, const int32_t length) const;

  double auto_drive_torque(const std::uint8_t* bytes, const int32_t length) const;

  int auto_drivercmd_alivecounter(const std::uint8_t* bytes, const int32_t length) const;

  int auto_drivercmd_checksum(const std::uint8_t* bytes, const int32_t length) const;

 private:
  Ads_drive_command_50::Drive_enableType drive_enable_;
  Ads_drive_command_50::Auto_shift_commandType auto_shift_command_;
  double auto_drive_torque_;
  int auto_drivercmd_alivecounter_;
  int auto_drivercmd_checksum_;
};

}  // namespace x3epro
}  // namespace canbus
}  // namespace apollo


